package com.ruoyi.bizsys.enums;

import com.ruoyi.bizsys.domain.AwardConfig;
import com.ruoyi.common.enums.RspEnmu;
import com.ruoyi.common.exception.BusinessException;

import java.math.BigDecimal;

/**
 * @author cyh
 * @date 2022/6/30 6:10 下午
 */
public enum AwardMethodEnum {

    /**
     * 现金
     */
    CASH("0"),

    /**
     * 现金比例
     */
    CASH_RATIO("1");


    private String eventValue;

    AwardMethodEnum(String eventValue) {
        this.eventValue = eventValue;
    }

    public String getEventValue() {
        return this.eventValue;
    }

    /**
     * @param awardConfig
     * @param awardPrincipal
     * @Param
     */
    public static BigDecimal conversion(AwardConfig awardConfig, BigDecimal awardPrincipal) {
        if (awardConfig.getAwardMethod().equals(CASH.getEventValue())) {
            return new BigDecimal(String.valueOf(awardConfig.getAwardValue()));
        }
        if (awardConfig.getAwardMethod().equals(CASH_RATIO.getEventValue())) {
            return awardPrincipal.multiply(new BigDecimal(String.valueOf(awardConfig.getAwardValue()))).multiply(new BigDecimal("0.01")).setScale(4);
        }
        throw new BusinessException(RspEnmu.SYSTEM_ERR);
    }

}

